<?php
$id= array(
	'name'	=> 'id',
	'id'	=> 'id',
	'value'	=> set_value('id', $user->id),
	'size'	=> 10,
	'disabled'	=> 'disabled',
);
$email= array(
	'name'	=> 'email',
	'id'	=> 'email',
	'value'	=> set_value('email', $user->email),
	'size'	=> 30,
);
$password= array(
	'name'	=> 'password',
	'id'	=> 'password',
	'value'	=> set_value('password', ''),
	'size'	=> 30,
);
$confirm_password= array(
	'name'	=> 'confirm_password',
	'id'	=> 'confirm_password',
	'value'	=> set_value('confirm_password', ''),
	'size'	=> 30,
);
$first_name= array(
	'name'	=> 'first_name',
	'id'	=> 'first_name',
	'value'	=> set_value('first_name', $user->user_profile->first_name),
	'maxlength'	=> 45,
	'size'	=> 30,
);
$middle_name = array(
	'name'	=> 'middle_name',
	'id'	=> 'middle_name',
	'value' => set_value('middle_name', $user->user_profile->middle_name),
	'maxlength'	=> 1,
	'size'	=> 3,
);
$last_name = array(
	'name'	=> 'last_name',
	'id'	=> 'last_name',
	'value' => set_value('last_name', $user->user_profile->last_name),
	'maxlength'	=> 45,
	'size'	=> 30,
);
$alias = array(
	'name'	=> 'alias',
	'id'	=> 'alias',
	'value' => set_value('alias', $user->user_profile->alias),
	'maxlength'	=> 45,
	'size'	=> 30,
);
$location = array(
	'name'	=> 'location',
	'id'	=> 'location',
	'value' => set_value('location', $user->user_profile->location),
	'maxlength'	=> 100,
	'size'	=> 30,
);
$web = array(
	'name'	=> 'web',
	'id'	=> 'web',
	'value' => set_value('web', $user->user_profile->web),
	'maxlength'	=> 100,
	'size'	=> 30,
);
$avatar = $user->user_profile->avatar;
$country = $user->user_profile->country->id;

?>
<div class="top shadow">
</div>

<div class="content">
	<?=$user_menu?>
	<table id="form-profile-container" cellspacing="20px">
		<tr>
			<th>
				Your user account<br/>
			</th>
			<td>
				<table class="form-table">
					<tr>
						<td class="label">Username:</td>
						<td><strong><?=$user->username?></strong><br/><div id="status"></div></td>
					</tr>
					<tr>
						<td class="label">Email account:</td>
						<td>
							<?=$user->email?>.&nbsp;<a href="/auth/change_email">Change email</a>
						</td>
					</tr>
					<tr>
						<td class="label">Password:</td>
						<td><a href="/auth/change_password">Change password</a></td>
					</tr>
				</table>
			</td>
		</tr>
		<?=form_open($this->uri->uri_string().'/update')?>
		<tr>
			<th>Your personal profile</th>
			<td>
				<table class="form-table">
					<tr>
						<td class="label"><?=form_label('First Name', 'first_name')?>:</td>
						<td>
							<?=form_input($first_name)?><br/>
							<span class="form-error"><?=form_error($first_name['name'])?></span>
						</td>
					</tr>
					<tr>
						<td class="label"><?=form_label('Middle Name', 'middle_name')?>:</td>
						<td>
							<?=form_input($middle_name)?><br/>
							<span class="form-error"><?=form_error($middle_name['name'])?></span>
						</td>
					</tr>
					<tr>
						<td class="label"><?=form_label('Last Name', 'last_name')?>:</td>
						<td>
							<?=form_input($last_name)?><br/>
							<span class="form-error"><?=form_error($last_name['name'])?></span>
						</td>
					</tr>
					<tr>
						<td class="label"><?=form_label('Alias', 'alias')?>:</td>
						<td>
							<?=form_input($alias)?><br/>
							<span class="form-error"><?=form_error($alias['name'])?></span>
						</td>
					</tr>
					<tr>
						<td class="label"><?=form_label('Location', 'location')?>:</td>
						<td>
							<?=form_input($location)?><br/>
							<span class="form-error"><?=form_error($location['name'])?></span>
						</td>
					</tr>
					<tr>
						<td class="label"><?=form_label('Country', 'country')?>:</td>
						<td>
							<?=form_dropdown('country', $countries, $country)?>
							<span class="form-error"><?=form_error('country')?></span>
						</td>
					</tr>
					<tr>
						<td class="label"><?=form_label('Web', 'web')?>:</td>
						<td>
							<?=form_input($web)?><br/>
							<span class="form-error"><?=form_error($web['name'])?></span>
						</td>
					</tr>
					<tr>
						<td class="label vtop"><?=form_label('Avatar', 'avatar')?>:</td>
						<td>
							<?=form_dropdown('avatar', $avatar_list, $avatar)?>
							<span class="form-error"><?=form_error('avatar')?></span>
						
						<?php 
							if(!is_null($user->user_profile->gravatar)) {
								$src = $this->gravatar->get($user->profile->gravatar, FALSE);
							} else {
								$src = (!is_null($avatar)) ? $this->imageene->get_avatar_path($avatar) : $this->gravatar->get("", FALSE);
							}
						?>
						
						<?=form_checkbox('use_gravatar', 'use_gravatar', (!is_null($user->user_profile->gravatar)))?>
						<?=form_label('Use Gravatar image instead.', 'avatar')?> <a class="reduced-font" href="http://gravatar.com/">Learn more</a>

						<span class="form-error"><?=form_error('use_gravatar')?></span>
						<br /><br />
						<?php if ($src) : ?>
						<img src="<?=$src?>" alt="<?=$user->username?>" title="<?=$user->username?>" class="avatar" />
						<?php endif; ?>
					</td>
					</tr>
				</table>
			</td>
		</tr>
		<tr>
			<th>
				Your mailing preferences<br/>
			</th>
			<td>
				<?=form_checkbox('mailing', 'mailing', TRUE)?>
				<?=form_label('I would like to receive emails containing news about Imageene.org', 'mailing')?>
			</td>
		</tr>
		<tr>
			<th>Other information</th>
			<td>
				Member since: <strong><?=$user->created?></strong><br />
				Last profile update: <strong><?=$user->user_profile->updated?></strong><br /><br/>
				<a href="/auth/unregister">Delete my account</a>
			</td>
		</tr>
		<tr>
			<th>&nbsp;</th>
			<td><br/><?=form_submit('submit-profile', 'Update profile!')?><br/><br/></td>
		</tr>
		<?=form_close()?>
	</table>
</div>


<?php if(!is_null($user->user_profile->id)) : ?>
<script>
/*
 $(function(){
$( "#dialog-create-profile" ).dialog({
	resizable: false,
	modal: true,
	buttons: {
		"Create profile": function() {
			$( this ).dialog( "close" );
			
		},
		"Not now": function() {
			$( this ).dialog( "close" );
			location.href='cpanel';
		}
	}
});
});*/
</script>

<?php endif; ?>


<!-- <div id="dialog-create-profile" title="User's profile"> -->
<!-- <p><span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 20px 0;"></span>-->
<!-- 	Your user's profile is still missing...<br/><br/>Do you want to create it now?</p> -->
<!-- </div> -->
